#ifndef UPLOADWIDGET_H
#define UPLOADWIDGET_H

#include <QDialog>
#include "product.h"
#include "excelimportthread.h"
#include "productservice.h"
#include "userrelationservice.h"
#include "userservice.h"

namespace Ui {
class UploadWidget;
}

class UploadWidget : public QDialog
{
    Q_OBJECT

public:
    explicit UploadWidget(QWidget *parent = nullptr);
    ~UploadWidget();

    void setWidgetType(int widgetType);

    void showAndInit();

    bool dealProductImportData(QList<QList<QVariant>> data);

    bool dealUserRelationImportData(QList<QList<QVariant>> data, UserRelation::RelationType type);

    void dealUploadSuccess();
signals:
    void importData();

private slots:
    void on_pushButtonOpenFile_clicked();

    void on_pushButtonUpload_clicked();

    void dealImportData(QList<QList<QVariant>> data);

private:
    Ui::UploadWidget *ui;

    QList<QList<Product*>> allProducts;
    QList<QList<UserRelation*>> allRelations;

    int curBatch;
    int totalBatch;
    int totalSize;
    double totalMoney;
    int widgetType;

    QThread *thread;
    ExcelImportThread *importThread;

    ProductService productService;
    UserRelationService userRelationService;
    UserService userService;
};

#endif // UPLOADWIDGET_H
